package com.example.ignite;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;

public class IgniteCluster3 {
    public static void main(String[] args) throws InterruptedException {
        IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
        igniteConfiguration.setClientMode(true);
        String cacheName = "myCache";
        CacheConfiguration cacheConfiguration = new CacheConfiguration(cacheName);
        cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
        cacheConfiguration.setBackups(2);
        cacheConfiguration.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
        cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        igniteConfiguration.setCacheConfiguration(cacheConfiguration);
        Ignite ignite = Ignition.start();
        IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheName);
        System.out.println(System.currentTimeMillis() + " IgniteCluster3 start OK.");
        System.out.println(System.currentTimeMillis() + cache.get(1));
        cache.put(1, " ignite3");
        while(true){
            System.out.println(System.currentTimeMillis() + cache.get(1));
            Thread.sleep(2000);
        }
    }
}